#include "Timer.h"
using namespace std;



Timer::Timer () {
	startTicks = 0;
	pausedTicks = 0;
	paused = false;
	started = false; 
}

int Timer::get_ticks() {
	
	    if( started == true )
	    {
	       
	        if( paused == true )
	        {
	            return pausedTicks;
	        }
	        else
	        {
	        	int ret = SDL_GetTicks() - startTicks;
	        	return ret;
	        }    
	    }
	    
	    return 0;
}

bool Timer::is_paused() {
	return paused;
}

bool Timer::is_started() {
	return started;
}

void Timer::pause() {
	
	if(started == true && paused ==false){
	paused = true;
	pausedTicks = SDL_GetTicks() - startTicks;
	}
}

void Timer::start() {
	started = true;
	paused = false;
	startTicks = SDL_GetTicks(); 
	
}

void Timer::stop() {
	started = false;
	paused = false;
}

void Timer::unpause() {
	if( paused == true )
	    {
	        paused = false;
	    
	        startTicks = SDL_GetTicks() - pausedTicks;
	        
	        pausedTicks = 0;
	    }
}